<template>
  <el-tabs v-model="activeName">
    <slot name="header"></slot>
    <el-tab-pane label="项目信息" name="file">
      <info-view :related-data="relatedData"></info-view>
    </el-tab-pane>
    <el-tab-pane label="放款登记">
      <register-reply :query-id="queryId" :view-mode="true"></register-reply>
    </el-tab-pane>
    <el-tab-pane label="合同附件">
      <contract-guard-view :query-id="queryId"></contract-guard-view>
    </el-tab-pane>
    <el-tab-pane label="放款通知书">
      <loan-notice :query-id="queryId"></loan-notice>
    </el-tab-pane>
    <el-tab-pane label="项目附件">
      <attach-view :query-id="queryId" :visible="visible"></attach-view>
    </el-tab-pane>
    <el-tab-pane label="贷后附件">
      <postloan-attach :query-id="queryId"></postloan-attach>
    </el-tab-pane>
  </el-tabs>
</template>

<script>
import ContractGuardView from '@/credit/views/county/unionProvince/components/ContractGuardView'
import AttachView from '@/credit/components/AttachView'
import PostloanAttach from '@/credit/views/city/mission/postloan/PostloanAttach'
import RegisterReply from '@/bigcredit/views/self/fast/register/components/RegisterReply'
import InfoView from '@/credit/views/city/bus/normal/Info'
import LoanNotice from '@/credit/views/county/unionProvince/components/LoanNotice'
export default {
  components: {
    ContractGuardView,
    AttachView,
    PostloanAttach,
    RegisterReply,
    InfoView,
    LoanNotice,
  },
  props: {
    visible: Boolean,
    relatedData: Object,
    tabName: {
      type: String,
      default: 'file',
    },
  },
  computed: {
    queryId() {
      return this.relatedData.customer_related_id
    },
  },
  watch: {
    relatedData: {
      handler: function () {
        this.activeName = this.tabName
        this.getContract(this.queryId)
      },
      deep: true,
    },
    tabName(val) {
      this.activeName = val
    },
  },
  data() {
    return {
      activeName: this.tabName,
      contractLoading: false,
    }
  },
  methods: {
    async getContract(relatedId) {
      if (!relatedId) return
      this.contractLoading = true
      await this.$utils.promise(
        Promise.all([
          this.$store.dispatch('getEntrustContract', relatedId),
          this.$store.dispatch('getGuardsData', relatedId),
        ])
      )
      this.contractLoading = false
    },
  },
}
</script>

<style></style>
